<?php
require_once("graficolinux/src/jpgraph.php");
require_once("graficolinux/src/jpgraph_bar.php");

function separator1000($aVal) 
{
    return number_format($aVal,0,',','.');
}

function separator1000_usd($aVal) 
{
    return '$'.number_format($aVal,0,',','.');
}

extract($_POST);
$datos1 = array(0=>'Enero',1=>'Febrero',2=>'Marzo',3=>'Abril',4=>'Mayo',5=>'Junio',6=>'Julio',7=>'Agosto',8=>'Septiembre',9=>'Octubre',10=>'Noviembre',11=>'Diciembre');
$datos2 = array();
$datos3 = array();
$datos4 = array();

$ventas = $_GET['ventas'];
$anuladas = $_GET['anuladas'];
$nopagadas = $_GET['nopagadas'];

$vec1 = explode(",",$ventas);
$vec2 = explode(",",$anuladas);
$vec3 = explode(",",$nopagadas);

//$vec1 = explode(",",'juan,pablo,mario,pedro,alejandro');
//$vec2 = explode(",",'3.09,2.98,2.72,4,6');

$j=0;$k=0;$n=0;
//vector ventas
for($i=0;$i<count($vec1);$i++)
{
	if($vec1[$i]!='')
	{	
		$datos2[$j] = $vec1[$i];
		$j++;
	}
}
//vector anuladas
for($m=0;$m<count($vec2);$m++)
{
	if($vec2[$m]!='')
	{	
		$datos3[$k] = $vec2[$m];
		$k++;
	}
}
//vector no pagadas
for($m=0;$m<count($vec3);$m++)
{
	if($vec3[$m]!='')
	{	
		$datos4[$n] = $vec3[$m];
		$n++;
	}
}
//datos
//$datay1=array(140,110,50,60);
//$datay2=array(35,90,190,190);

$graph = new Graph(730, 760, "auto");    
//$graph->SetScale( "textlin");
$graph->SetAngle(90);
//$graph->SetScale("textlin",0,100000000);
$graph->SetScale("textlin",0,0);
//$graph->SetY2Scale('lin',0,0);

$graph->img->SetMargin(110, 100, 150, 50);//izquierda, derecha, arriba, abajo
$graph->title->Set("Libro de Ventas Anual");
$graph->title->SetFont(FF_VERDANA,FS_NORMAL,13);
$graph->title->SetMargin(20);
//$graph->yaxis->title->Set("Monto $");
//$graph->xaxis->title->Set("Meses");

$graph->xaxis->title->SetFont(FF_VERDANA,FS_NORMAL,10);
$graph->yaxis->title->SetMargin(10);
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#F9BB64@0.5'); 
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
$graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,7);
//$graph->xaxis->SetLabelAngle(70);
$graph->yaxis->SetLabelAngle(70);

$graph->xaxis->SetTickLabels($datos1);
$graph->xaxis->SetLabelMargin(45);

$graph->yaxis->SetLabelSide(SIDE_RIGHT);
$graph->yaxis->SetLabelAlign('center','bottom');
$graph->yaxis->SetLabelMargin(-3);

//$graph->y2axis->SetTickSide(SIDE_RIGHT);

//$graph->xaxis->SetLabelAlign('lefth','center');
// posicion de la leyenda
$graph->legend->Pos(0.03,0.03);

// Adjust the color for theshadow of the legend
$graph->legend->SetShadow('darkgray@0.5');
$graph->legend->SetFillColor('lightblue@0.3');
$graph->legend->SetFont(FF_VERDANA,FS_NORMAL,8);
$graph->yaxis->SetLabelFormatCallback('separator1000');
// Create the three var series we will combine
$bplot1 = new BarPlot($datos2);
$bplot2 = new BarPlot($datos3);
$bplot3 = new BarPlot($datos4);
//$bplot1->value->Show();
//$bplot2->value->Show();
//$bplot1->value->SetColor('darkred');
//$bplot2->SetFillColor('darkred');

//$bplot1->SetShadow();
//$bplot1->value->SetFormat(" $ %d");
$bplot1->value->SetFont(FF_VERDANA,FS_NORMAL,7);
$bplot1->value->SetColor("blue");
$bplot1->value->Show();

//$bplot2->SetShadow();
//$bplot2->value->SetFormat(" $ %d");
$bplot2->value->SetFont(FF_VERDANA,FS_NORMAL,7);
$bplot2->value->SetColor("darkgreen");
$bplot2->value->Show();

//$bplot3->SetShadow();
//$bplot2->value->SetFormat(" $ %d");
$bplot3->value->SetFont(FF_VERDANA,FS_NORMAL,7);
$bplot3->value->SetColor("red");
$bplot3->value->Show();

$bplot1->value->SetFormatCallback('separator1000_usd');
$bplot2->value->SetFormatCallback('separator1000_usd');
$bplot3->value->SetFormatCallback('separator1000_usd');
// Setup the colors with 40% transparency (alpha channel)
$bplot1->SetFillColor('blue@0.4');
$bplot2->SetFillColor('darkgreen@0.4');
$bplot3->SetFillColor('red@0.4');

// Setup legends
$bplot1->SetLegend('Fac. Pagadas');
$bplot2->SetLegend('Fac. Anuladas');
$bplot3->SetLegend('Fac. No Pagadas');

// Setup each bar with a shadow of 50% transparency
//$bplot1->SetShadow('black@0.3');
//$bplot2->SetShadow('black@0.3');
//$bplot3->SetShadow('black@0.3');

$gbarplot = new GroupBarPlot(array($bplot1,$bplot3,$bplot2));
$gbarplot->SetWidth(0.8);
$graph->Add($gbarplot);

$graph->Stroke();
?> 